package www.shuang.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import www.shuang.common.util.PageInfoUtil;
import www.shuang.system.dao.IACateDao;
import www.shuang.system.pojo.ACate;
import www.shuang.system.service.IAcateService;

@Service("cateService")
public class ACateServiceImpl implements IAcateService
{	@Resource
	protected IACateDao cateDao;
	@Override
	public ACate findOneACateService(Map<String, Object> condMap)
	{
		return this.cateDao.findOne(condMap);
	}

	@Override
	public List<ACate> findCondListACateService(PageInfoUtil pageInfoUtil, Map<String, Object> condMap)
	{
		
		List<ACate> cateList=new ArrayList<ACate>();
		//处理关键字
		if(condMap.get("keyword") != null){
			condMap.put("keyword", "%"+condMap.get("keyword")+"%");
		}
		if(pageInfoUtil != null){
			//分页查询
			condMap.put("pageCount", "true");
			cateList=this.cateDao.findCondList(condMap);
			//分页,总记录数放在了id属性上
			pageInfoUtil.setTotalRecord(cateList.get(0).getId());
			//拿分页数据
			condMap.put("pageCount","false");
			//每页有多少记录
			condMap.put("currentRecord", pageInfoUtil.getCurrRecord());
			condMap.put("pageSize", pageInfoUtil.getPageSize());
			cateList=this.cateDao.findCondList(condMap);
			
		}else{
			cateList=this.cateDao.findCondList(condMap);
		}
		
		
		return cateList;
	}

	@Override
	public JSONObject insertOneACateService(ACate cate)
	{
		
		JSONObject resultJSON=new JSONObject();
		int res=this.cateDao.insert(cate);
	if(res>0){
		resultJSON.put("code", "0");
		resultJSON.put("info", "添加成功");
		//添加二级json
		JSONObject dataJSON=new JSONObject();
		dataJSON.put("affect",res);
		resultJSON.put("data", dataJSON);
	}else{
		resultJSON.put("code", "1");
		resultJSON.put("info", "添加失败");
	}
	
	return resultJSON;
	}

	@Override
	public JSONObject updateOneACateService(ACate cate)
	{
		
		return null;
	}

	@Override
	public JSONObject deleteOneACateService(ACate cate)
	{
		// TODO Auto-generated method stub
		return null;
	}

}
